<?php

// +----------------------------------------------------------------------
// | TAODUDU.COM  [ Simple Efficient Excellent ]
// +----------------------------------------------------------------------
// | Copyright (c) 2016 http://www.taodudu.com All rights reserved.
// +----------------------------------------------------------------------
// | Author: ubten <462193409@qq.com> http://www.ubten.com/
// +----------------------------------------------------------------------

namespace Admin\Controller;
use Admin\Controller\AdminController;
class KeywordController extends AdminController {

    function _initialize() {
        parent::_initialize();
        $this->assign('action', 'keyword');
        $this->assign('sys', 'website'); // 数据集
    }
    
    //品牌列表
    public function index(){
        
        $title = I('title');
        if(!empty($title)){
            $where['k_title'] = array('like','%'.$title.'%');
        }
        $Brand = M("keywords");
        $count = $Brand->where($where)->count();
        $Page = new \Think\Page($count, 15); // 实例化分页类 传入总记录数和每页显示的记录数(25)
        $show = $Page->show(); // 分页显示输出
        $arr = $Brand->where($where)->order('k_order asc')->limit($Page->firstRow . ',' . $Page->listRows)->select();
        $this->assign('pages',$show);
        $this->assign('arr',$arr);
        $this->assign('title',$title);
        $this->display();
    }
    
    
    public function add(){
        if(IS_POST){
            $data['k_title'] = I('k_title');
            $data['k_order'] = I('k_order');
            $data['k_color'] = I('k_color');
            $data['k_strong'] = I('k_strong');
            $re = M('keywords')->add($data);
            if($re){
                $this->success('关键词添加成功！',U('index'));
            }else{
                $this->error('关键词添加失败！');
            }
        }
        $this->display();
    }
    
    
    public function edit(){
        $id = I('k_id');
        $map['k_id'] = $id;
        if(IS_POST){
            $data['k_title'] = I('k_title');
            $data['k_order'] = I('k_order');
            $data['k_color'] = I('k_color');
            $data['k_strong'] = I('k_strong');
            $re = M('keywords')->where($map)->save($data);
            if($re){
                $this->success('关键词修改成功！',U('index'));
            }else{
                $this->error('关键词修改失败！');
            }
        }
        $rs = M('keywords')->where($map)->find();
        $this->assign('rs',$rs);
        $this->display();
    }
    
    public function del(){
        $Id = I('post.data', 0, 'intval');
        if (empty($Id)) {
            $this->error('关键词不能为空！');
        }
        if (M('keywords')->where('k_id=' . $Id)->delete()) {
            $this->success('删除成功！', U('index'));
        } else {
            $this->error('删除失败！');
        }
    }
    
    
    
    
    
}
